function integralProgramme() {
    var _this = this;
    var page;
    _this.obj = null;

    _this.init = function (page_data) {
        page = page_data;
        _this.initTable();
    };

    _this.initTable = function () {
        var list_url = appPath + "/admin/integralProgramme/queryList";
        page.init("integral_programme_form", list_url, "integral_programme_table", "integral_programme_page", 1, 10);
        page.goPage(1);
        page.list = function (dataList) {
            $("#checkAll").attr("checked", false);
            var len = dataList.length;
            _this.obj = dataList;
            var inner = "", item;
            // 组装数据
            for (var i = 0; i < len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td width="40">' + (i + 1) + '</td>';
                inner += '<td width="120">' + item['varName'] + '</td>';
                inner += '<td width="120">' + _this.tool2tip(item['introduction']) + '</td>';
                inner += '<td width="80">' + TimeUtil.longMsTimeConvertToDateTime(item['startTime'])+ '</td>';
                inner += '<td width="80">' + TimeUtil.longMsTimeConvertToDateTime(item['endTime']) + '</td>';
                inner += '<td width="80">' + item['createUser'] + '</td>';
                inner += '<td width="80">' + TimeUtil.longMsTimeConvertToDateTime(item['createTime']) + '</td>';
                if(item['status']=='1'){
                    inner += '<td width="60">未发布</td>';
                } else {
                    inner += '<td width="60">已发布</td>';
                }
                if(item['isUse']=='1'){
                    inner += '<td width="60">禁用</td>';
                } else {
                    inner += '<td width="60">启用</td>';
                }
                inner += "<td width='300'>";
                inner += "<a href=javascript:integralProgramme.view('"+item.id+"') class='a a-view'>详情</a>&nbsp;";
                inner += "<a href=javascript:integralProgramme.edit('"+item.id+"') class='a a-info'>编辑</a>&nbsp;";
                inner += "<a href=javascript:integralProgramme.delete('"+item.id+"') class='a a-close'>删除</a>&nbsp;";
                if(item['isUse']=='1'){
                    inner += "<a href=javascript:integralProgramme.updateIsUse('"+item.id+"','2','启用') class='a a-info'>启用</a>&nbsp;";
                } else {
                    if(item['status']=='1'){
                        inner += "<a href=javascript:integralProgramme.updateStatus('"+item.id+"','2','发布') class='a a-info'>发布</a>&nbsp;";
                    } else {
                        inner += "<a href=javascript:integralProgramme.updateStatus('"+item.id+"','1','取消发布') class='a a-close'>取消发布</a>&nbsp;";
                    }
                    inner += "<a href=javascript:integralProgramme.updateIsUse('"+item.id+"','1','禁用') class='a a-close'>禁用</a>&nbsp;";
                }
                inner += "</td>";
                inner += '</tr>';
            }
            return inner;
        }
    };

    _this.add = function () {
        window.location.href = appPath + "/admin/integralProgramme/add";
    };

    _this.view = function (id) {
        window.location.href = appPath + "/admin/integralProgramme/view?id="+id;
    };

    _this.edit = function (id) {
        window.location.href = appPath + "/admin/integralProgramme/edit?id="+id;
    };

    _this.delete = function (id) {
        layer.confirm('确定要删除选择的数据吗？', {btn: ['是', '否']}, function (index) {
            $.ajax({
                url: appPath + "/admin/integralProgramme/delete",
                dataType: "json",
                async: true,
                type: "POST",
                data: { "id": id },
                success:function(data){
                    var result = data.code;
                    if (10000 == result) {
                        layer.alert('操作成功', {icon : 1, closeBtn:0},function (index) {
                            layer.close(index);
                            //刷新课程列表
                            _this.initTable();
                        });
                    } else {
                        layer.alert('操作失敗', {icon : 2});
                    }
                }
            });
        });
    };

    _this.updateStatus = function (id,status,msg) {
        layer.confirm('确定要'+msg+'吗？', {btn: ['是', '否']}, function (index) {
            $.ajax({
                url: appPath + "/admin/integralProgramme/updateStatus",
                dataType: "json",
                async: true,
                type: "POST",
                data: { "id": id, "status": status},
                success:function(data){
                    if (10000 == data.code) {
                        layer.alert(data.message, {icon : 1, closeBtn:0},function (index) {
                            layer.close(index);
                            //刷新课程列表
                            _this.initTable();
                        });
                    } else {
                        layer.alert(data.message, {icon : 2});
                    }
                }
            });
        });
    };

    _this.updateIsUse = function (id,isUse,msg) {
        layer.confirm('确定要'+msg+'吗？', {btn: ['是', '否']}, function (index) {
            $.ajax({
                url: appPath + "/admin/integralProgramme/updateIsUse",
                dataType: "json",
                async: true,
                type: "POST",
                data: { "id": id, "isUse": isUse},
                success:function(data){
                    if (10000 == data.code) {
                        layer.alert(data.message, {icon : 1, closeBtn:0},function (index) {
                            layer.close(index);
                            //刷新课程列表
                            _this.initTable();
                        });
                    } else {
                        layer.alert(data.message, {icon : 2});
                    }
                }
            });
        });
    };

    _this.tool2tip = function (data) {
        if(null == data || "" == data){
            return "";
        }
        var data1 = data.length >= 15 ? data.substring(0,15) + "...": data;
        var html = '<a href="javascript:;" class="dropdown-toggle" data-toggle="tooltip" title="'+ data +'">'+ data1 +'</a>';
        return html;
    };

    _this.search = function () {
        _this.initTable();
    };

    _this.searchAll = function () {
        $("#searchVarName").val('');
        _this.initTable();
    };

}

var integralProgramme = new integralProgramme();